package designPattern;

/**
 * 装饰器/包装器模式
 */
public class DecoratorPattern {
    public static void main(String[] args) {
        Shape circle = new Circle();
        Shape redCircle = new RedShapeDecorator(new Circle());
        Shape redRectangle = new RedShapeDecorator(new Rectangle());

        circle.draw();
        redCircle.draw();
        redRectangle.draw();
    }
}

interface Shape {
    void draw();
}

class Rectangle implements Shape {
    @Override
    public void draw() {
        System.out.println("Shape : Rectangle");
    }
}

class Circle implements Shape {

    @Override
    public void draw() {
        System.out.println("Shape : Circle");
    }
}

abstract class ShapeDecorator implements Shape {
    protected Shape decoratorShape;

    ShapeDecorator(Shape decoratorShape) {
        this.decoratorShape = decoratorShape;
    }

    public void draw() {
        this.decoratorShape.draw();
    }
}

class RedShapeDecorator extends ShapeDecorator {

    RedShapeDecorator(Shape decoratorShape) {
        super(decoratorShape);
    }

    @Override
    public void draw() {
        decoratorShape.draw();
        setRedShapeDecorator(decoratorShape);
    }

    private void setRedShapeDecorator(Shape decoratorShape) {
        System.out.println("Border color : Red");
    }
}